package _17_剑指Offer;

import _17_剑指Offer.datastrcute.ListNode;

public class _52_剑指Offer两个链表的第一个公共节点 {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;

        ListNode head1 = headA;
        ListNode head2 = headB;
        while (head1 != head2) {
            head1 = head1 == null? headB: head1.next;
            head2 = head2 == null? headA: head2.next;
        }
        return head1;
    }
}
